<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\HomeUser;

class HomeUserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        //
        $count = $request -> input('count',5);
        $search = $request -> input('search','');
        $request = $request -> all();
        // 查询数据并分页
        $data = HomeUser::where('username','like','%'.$search.'%')->paginate($count);
        return view('admin.homeuser.index',['data'=>$data,'request'=>$request]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * 前台用户详情
     *
     * @param  int  $id
     * @return 用户详情页面
     */
    public function show($id)
    {
        //
        $userinfo = HomeUser::find($id)->userinfo;
        $user = HomeUser::find($id);
        $order = \DB::table('sad_order')->where('uid',$id)->get();
        $goods = \DB::table('sad_goods')->where('uid',$id)->get();
        $order = count($order);
        $goods = count($goods);
        return view('admin.homeuser.show',compact('userinfo','user','order','goods'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
        $user = HomeUser::find($id);
        $user -> status = $user['status']==1 ? 0 : 1 ;
        $user -> save();
        return back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
